package com.leenmvc.core.security.dao.core;

import com.leenmvc.core.base.BaseBusinessDao;
import com.leenmvc.core.cache.CacheFactory;
import com.leenmvc.core.enums.CacheType;
import com.leenmvc.core.security.entity.core.SysTip;
import com.leenmvc.core.utils.http.HttpContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.Map;

@Repository
public class SysTipDao extends BaseBusinessDao<SysTip> {

    private final static Logger logger = LoggerFactory.getLogger(SysTipDao.class);

    public String getTip(String identification) {
        // 如果identification匹配到中文那么直接返回
        Map<String, Map<String, Map<String, Object>>> tips1 = CacheFactory.get(CacheType.GLOBAL_VARIABLE, "tips");
        Map<String, Map<String, Object>> sys_tip = tips1.get("sys_tip");
        if(sys_tip != null) {
            Map<String, Object> stringObjectMap = sys_tip.get(identification);
            if (stringObjectMap != null) {
                Object o = stringObjectMap.get(HttpContextUtils.getLanguage());
                if(o != null) {
                    return o.toString();
                }
            }
        }
        logger.info("将要查询的提示语标识符是 ：{}", identification);
        return getBySqlKey("getTip", "identification", identification, "language", HttpContextUtils.getLanguage());
    }

}
